from django.db import models
from xftinterfaces.models import *


class LocalIncomeType(models.Model):
    local_income_code = models.CharField(max_length=50, blank=True, null=True, verbose_name="所得类型代码")
    local_income_name = models.CharField(max_length=50, blank=True, null=True, verbose_name="所得类型名称")

    def __str__(self):
        return self.local_income_name

    class Meta:
        managed = True
        db_table = 'local_income_type'
        verbose_name_plural = '所得类型'
        verbose_name = '所得类型'


class LocalIncomeItems(models.Model):
    local_income_type = models.ForeignKey(LocalIncomeType, models.DO_NOTHING, default=1, db_constraint=False)
    local_income_items_code = models.CharField(max_length=50, blank=True, null=True, verbose_name="所得项目代码")
    local_income_items_name = models.CharField(max_length=50, blank=True, null=True, verbose_name="所得项目名称")

    def __str__(self):
        return self.local_income_items_name

    class Meta:
        managed = True
        db_table = 'local_income_items'
        verbose_name_plural = '所得项目'
        verbose_name = '所得项目'


class LocalSalary(models.Model):
    local_salary_emp_id = models.IntegerField(db_column='emp_id', verbose_name='员工id')
    local_salary_period = models.CharField(max_length=50, blank=True, null=True, verbose_name="所得项目代码")
    local_salary_standard_wages = models.FloatField(blank=True, null=True, verbose_name='应发合计')
    local_salary_items = models.ForeignKey(LocalIncomeItems, models.DO_NOTHING, default=1, verbose_name='所得类型', db_constraint=False)
    local_salary_endowment = models.FloatField(blank=True, null=True, verbose_name='个人养老')
    local_salary_injury = models.FloatField(blank=True, null=True, verbose_name='个人工伤')
    local_salary_lose = models.FloatField(blank=True, null=True, verbose_name='个人失业')
    local_salary_treat = models.FloatField(blank=True, null=True, verbose_name='个人医疗')
    local_salary_fund = models.FloatField(blank=True, null=True, verbose_name='个人公积金')
    local_salary_income_tax = models.FloatField(blank=True, null=True, verbose_name='个税')
    create_time = models.DateTimeField(blank=True, null=True, auto_now_add=True, editable=True, verbose_name='创建时间')
    modify_time = models.DateTimeField(blank=True, null=True, auto_now=True, editable=True, verbose_name='修改时间')

    def __str__(self):
        return self.local_salary_emp_id

    class Meta:
        managed = True
        db_table = 'local_salary'
        verbose_name_plural = '所得项目'
        verbose_name = '所得项目'


catxst_chioce_list = (
    ('1', "未算税"),
    ('2', "算税成功"),
    ('3', "算税中"),
    ('4', "算税失败"),
    ('5', "部分算税失败"),
)


class TaxCalcCreateReturn(models.Model):
    create_return_period = models.CharField(max_length=50, blank=True, null=True, verbose_name="计算周期")
    create_return_body = models.JSONField(blank=True, null=True, verbose_name="发送到薪福通的原始数据")
    # 批次组序号,薪福通自动生成，与BUSNBR一对一
    create_return_grpseq = models.CharField(max_length=50, blank=True, null=True, verbose_name="批次组序号")
    # 业务编号,对调用方来说，每次同步员工薪资即一个批次组，个税会根据不同税局、人数控制再拆分为细粒度批次对调用方来说，每次同步员工薪资即一个批次组，个税会根据不同税局、人数控制再拆分为细粒度批次
    create_return_busnbr = models.CharField(max_length=50, blank=True, null=True, verbose_name="业务编号")
    # 批次号	薪福通对应的批次号
    create_return_batpid = models.CharField(max_length=50, blank=True, null=True, verbose_name="批次号")
    create_return_batnam = models.CharField(max_length=50, blank=True, null=True, verbose_name="批次名称")
    # 算税状态	1未算税;2算税成功;3算税中;4算税失败;5部分算税失败
    create_return_catxst = models.CharField(max_length=1, blank=True, null=True, verbose_name="算税状态", choices=catxst_chioce_list)
    create_return_status = models.BooleanField(default=False, verbose_name="是否已删除")
    create_time = models.DateTimeField(blank=True, null=True, auto_now_add=True, editable=True, verbose_name='创建时间')
    modify_time = models.DateTimeField(blank=True, null=True, auto_now=True, editable=True, verbose_name='修改时间')

    def __str__(self):
        return self.create_return_period

    class Meta:
        managed = True
        db_table = 'tax_calc_create_return'
        verbose_name_plural = '算税批次创建返回值'
        verbose_name = '算税批次创建返回值'


errtyp_chioce_list = (
    ('1', "正确"),
    ('2', "为空"),
    ('3', "错误"),
    ('4', "其他")
)


class TaxCalcCreateFail(models.Model):
    # 批次组序号,薪福通自动生成，与BUSNBR一对一
    create_fail_period = models.CharField(max_length=50, blank=True, null=True, verbose_name="周期")
    create_fail_depnbr = models.CharField(max_length=50, blank=True, null=True, verbose_name="部门编码")
    create_fail_errtyp = models.CharField(max_length=1, blank=True, null=True, verbose_name="错误类型", choices=errtyp_chioce_list)
    create_fail_infdtl = models.CharField(max_length=255, blank=True, null=True, verbose_name="详情")
    create_fail_regseq = models.CharField(max_length=255, blank=True, null=True, verbose_name="登记序号")
    create_fail_depnam = models.CharField(max_length=255, blank=True, null=True, verbose_name="部门名称")
    create_fail_nicnam = models.CharField(max_length=255, blank=True, null=True, verbose_name="税务分局昵称")
    create_fail_prjnam = models.CharField(max_length=255, blank=True, null=True, verbose_name="企业名称")
    create_fail_taxorg = models.CharField(max_length=255, blank=True, null=True, verbose_name="主管税务机关名称")
    create_fail_wgznmr = models.CharField(max_length=255, blank=True, null=True, verbose_name="外管证编号")
    create_fail_taxsub = models.CharField(max_length=255, blank=True, null=True, verbose_name="主管税务分局所科名称")
    create_time = models.DateTimeField(blank=True, null=True, auto_now_add=True, editable=True, verbose_name='创建时间')
    modify_time = models.DateTimeField(blank=True, null=True, auto_now=True, editable=True, verbose_name='修改时间')

    def __str__(self):
        return self.create_fail_period

    class Meta:
        managed = True
        db_table = 'tax_calc_create_fail'
        verbose_name_plural = '算税批次创建税局错误信息接口'
        verbose_name = '算税批次创建税局错误信息接口'


lstdec_chioce_list = (
    ('1', "上月所得类型无申报记录"),
    ('2', "代报上月工资开关关闭，且上月所得类型有申报记录，但未成功进行申报")
)


class TaxCalcCreateFailEmp(models.Model):
    create_fail_emp_period = models.CharField(max_length=50, blank=True, null=True, verbose_name="周期")
    create_fail_emp_stfseq = models.CharField(max_length=50, blank=True, null=True, verbose_name="员工序号")
    create_fail_emp_apiseq = models.CharField(max_length=50, blank=True, null=True, verbose_name="源员工序号")
    create_fail_emp_regseq = models.CharField(max_length=50, blank=True, null=True, verbose_name="登记序号")
    create_fail_emp_busnbr = models.CharField(max_length=50, blank=True, null=True, verbose_name="业务编号")
    create_fail_emp_errtyp = models.CharField(max_length=1, blank=True, null=True, verbose_name="错误类型", choices=errtyp_chioce_list)
    create_fail_emp_errcod = models.CharField(max_length=50, blank=True, null=True, verbose_name="错误码")
    create_fail_emp_errmsg = models.CharField(max_length=50, blank=True, null=True, verbose_name="错误信息")
    create_fail_emp_stfnam = models.CharField(max_length=50, blank=True, null=True, verbose_name="姓名")
    create_fail_emp_certyp = models.CharField(max_length=1, blank=True, null=True, verbose_name="证件类型")
    create_fail_emp_cernbr = models.CharField(max_length=50, blank=True, null=True, verbose_name="证件号码")
    create_fail_emp_lstdec = models.CharField(max_length=1, blank=True, null=True, verbose_name="上月申报状态", choices=lstdec_chioce_list)
    create_time = models.DateTimeField(blank=True, null=True, auto_now_add=True, editable=True, verbose_name='创建时间')
    modify_time = models.DateTimeField(blank=True, null=True, auto_now=True, editable=True, verbose_name='修改时间')

    def __str__(self):
        return self.create_fail_emp_period

    class Meta:
        managed = True
        db_table = 'tax_calc_create_fail_emp'
        verbose_name_plural = '员工薪资错误信息输出接口'
        verbose_name = '员工薪资错误信息输出接口'


sys_errtyp_chioce_list = (
    ('0', "系统异常"),
    ('1', "业务异常")
)


class TaxCalcCreateFailSys(models.Model):
    create_fail_sys_period = models.CharField(max_length=50, blank=True, null=True, verbose_name="周期")
    create_fail_sys_busnbr = models.CharField(max_length=50, blank=True, null=True, verbose_name="业务编号")
    create_fail_sys_errmsg = models.CharField(max_length=50, blank=True, null=True, verbose_name="错误信息")
    create_fail_sys_errflg = models.CharField(max_length=1, blank=True, null=True, verbose_name="错误类型", choices=sys_errtyp_chioce_list)
    create_fail_sys_errcod = models.CharField(max_length=50, blank=True, null=True, verbose_name="错误码")
    create_fail_sys_errpam = models.CharField(max_length=50, blank=True, null=True, verbose_name="姓名")
    create_fail_sys_errdtl = models.CharField(max_length=1, blank=True, null=True, verbose_name="错误详细描述")
    create_time = models.DateTimeField(blank=True, null=True, auto_now_add=True, editable=True, verbose_name='创建时间')
    modify_time = models.DateTimeField(blank=True, null=True, auto_now=True, editable=True, verbose_name='修改时间')

    def __str__(self):
        return self.create_fail_sys_period

    class Meta:
        managed = True
        db_table = 'tax_calc_create_fail_sys'
        verbose_name_plural = '系统薪资错误信息输出接口'
        verbose_name = '系统薪资错误信息输出接口'


# 所得类型
inctyp_chioce_list = (
    ('1', "综合所得"),
    ('2', "分类所得"),
    ('3', "非居民所得")
)
# 所得项目
incite_chioce_list = (
    ('01', "正常工资薪金"),
    ('02', "全年一次性奖金收入"),
    ('03', "稿酬所得"),
    ('04', "一般劳务报酬所得"),
    ('05', "解除劳动合同一次性补偿金"),
    ('06', "保险营销员佣金收入"),
    ('07', "证券经纪人佣金收入"),
    ('08', "其他连续劳务报酬所得"),
    ('09', "个人股权激励收入"),
    ('10', "年金领取"),
    ('11', "其他非连续劳务报酬"),
    ('01', "上市公司股息红利所得（沪市、深市、创业板）"),
    ('09', "其他利息、股息、红利"),
    ('10', "其他财产转让所得"),
    ('11', "其他偶然所得"),
    ('12', "其他财产租赁所得"),
    ('13', "股权转让所得"),
    ('01', "无住所个人正常工资薪金"),
    ('02', "无住所个人数月奖金"),
    ('03', "稿酬所得"),
    ('04', "一般劳务报酬所得"),
    ('05', "其他利息、股息、红利所得"),
    ('06', "股权转让所得"),
    ('07', "其他财产转让所得"),
    ('08', "偶然所得"),
    ('12', "非居民股权激励所得"),
)


class TaxSearchResult(models.Model):
    search_result_period = models.CharField(max_length=50, blank=True, null=True, verbose_name="周期")
    search_result_stfnam = models.CharField(max_length=100, blank=True, null=True, verbose_name="姓名")
    search_result_natnlt = models.CharField(max_length=2, blank=True, null=True, verbose_name="国籍")
    search_result_certyp = models.CharField(max_length=1, blank=True, null=True, verbose_name="证件类型")
    search_result_cernbr = models.CharField(max_length=90, blank=True, null=True, verbose_name="证件号码")
    search_result_orgseq = models.CharField(max_length=4, blank=True, null=True, verbose_name="组织编号")
    search_result_regseq = models.CharField(max_length=30, blank=True, null=True, verbose_name="登记序号")
    search_result_durtax = models.CharField(max_length=6, blank=True, null=True, verbose_name="税款所属期")
    search_result_taxorg = models.CharField(max_length=80, blank=True, null=True, verbose_name="税务分局")
    search_result_prjnam = models.CharField(max_length=80, blank=True, null=True, verbose_name="企业名称")
    search_result_depnam = models.CharField(max_length=80, blank=True, null=True, verbose_name="备案部门名称")
    search_result_depnbr = models.CharField(max_length=30, blank=True, null=True, verbose_name="备案部门编码")
    search_result_inctyp = models.CharField(max_length=1, blank=True, null=True, verbose_name="所得类型", choices=inctyp_chioce_list)
    search_result_isbmba = models.CharField(max_length=1, blank=True, null=True, verbose_name="是否分部门备案")
    search_result_nicnam = models.CharField(max_length=80, blank=True, null=True, verbose_name="税务分局昵称")
    search_result_incite = models.CharField(max_length=2, blank=True, null=True, verbose_name="所得项目", choices=incite_chioce_list)
    search_result_groinc = models.CharField(max_length=100, blank=True, null=True, verbose_name="收入总额")
    search_result_ybtsef = models.CharField(max_length=100, blank=True, null=True, verbose_name="应补(退)税额")
    search_result_jcfyfd = models.CharField(max_length=100, blank=True, null=True, verbose_name="减除费用")
    search_result_crmssd = models.CharField(max_length=100, blank=True, null=True, verbose_name="免税收入")
    search_result_jbylbx = models.CharField(max_length=100, blank=True, null=True, verbose_name="基本养老保险费")
    search_result_jbyibx = models.CharField(max_length=100, blank=True, null=True, verbose_name="基本医疗保险费")
    search_result_syvxye = models.CharField(max_length=100, blank=True, null=True, verbose_name="基本失业保险费")
    search_result_zfgjjy = models.CharField(max_length=100, blank=True, null=True, verbose_name="基本住房公积金")
    search_result_annuty = models.CharField(max_length=100, blank=True, null=True, verbose_name="年金")
    search_result_syjkbx = models.CharField(max_length=100, blank=True, null=True, verbose_name="商业健康保险")
    search_result_syylbx = models.CharField(max_length=100, blank=True, null=True, verbose_name="税延养老保险")
    search_result_qtkchj = models.CharField(max_length=100, blank=True, null=True, verbose_name="其他扣除")
    search_result_fudval = models.CharField(max_length=100, blank=True, null=True, verbose_name="财产原值")
    search_result_othinf = models.CharField(max_length=100, blank=True, null=True, verbose_name="其他")
    search_result_yykcsf = models.CharField(max_length=100, blank=True, null=True, verbose_name="其他允许扣除税费")
    search_result_zykcjk = models.CharField(max_length=100, blank=True, null=True, verbose_name="准予扣除的捐赠额")
    search_result_jmsezd = models.CharField(max_length=100, blank=True, null=True, verbose_name="减免税额")
    search_result_ljykjn = models.CharField(max_length=100, blank=True, null=True, verbose_name="累计应扣缴税额")
    search_result_ljyjse = models.CharField(max_length=100, blank=True, null=True, verbose_name="累计已扣缴税额")
    search_result_ykjsef = models.CharField(max_length=100, blank=True, null=True, verbose_name="应扣缴税额")
    search_result_yjsefd = models.CharField(max_length=100, blank=True, null=True, verbose_name="已缴税额")
    search_result_ljsref = models.CharField(max_length=100, blank=True, null=True, verbose_name="累计收入")
    search_result_ljjcfy = models.CharField(max_length=100, blank=True, null=True, verbose_name="累计减除费用")
    search_result_ljzxkc = models.CharField(max_length=100, blank=True, null=True, verbose_name="累计专项扣除")
    search_result_ljyyef = models.CharField(max_length=100, blank=True, null=True, verbose_name="累计婴幼儿照护费用")
    search_result_ljznjy = models.CharField(max_length=100, blank=True, null=True, verbose_name="累计专项附加扣除子女教育")
    search_result_ljsylr = models.CharField(max_length=100, blank=True, null=True, verbose_name="累计专项附加扣除赡养老人")
    search_result_ljzflx = models.CharField(max_length=100, blank=True, null=True, verbose_name="累计住房贷款利息")
    search_result_ljzfzj = models.CharField(max_length=100, blank=True, null=True, verbose_name="累计专项附加扣除住房租金")
    search_result_ljjxjy = models.CharField(max_length=100, blank=True, null=True, verbose_name="累计专项附加扣除继续教育")
    search_result_lzxfjk = models.CharField(max_length=100, blank=True, null=True, verbose_name="累计专项附加扣除合计")
    search_result_ljqkce = models.CharField(max_length=100, blank=True, null=True, verbose_name="累计其他扣除")
    search_result_ljzykd = models.CharField(max_length=100, blank=True, null=True, verbose_name="累计准予扣除的捐赠额")
    search_result_ynssde = models.CharField(max_length=100, blank=True, null=True, verbose_name="应纳税所得额")
    search_result_sskcsf = models.CharField(max_length=100, blank=True, null=True, verbose_name="速算扣除数")
    search_result_ynsefd = models.CharField(max_length=100, blank=True, null=True, verbose_name="应纳税额")
    search_result_taxrat = models.CharField(max_length=100, blank=True, null=True, verbose_name="税率")
    search_result_remark = models.CharField(max_length=255, blank=True, null=True, verbose_name="备注")
    search_result_ptsism = models.CharField(max_length=100, blank=True, null=True, verbose_name="税前扣除项目合计")
    search_result_sfctrt = models.CharField(max_length=100, blank=True, null=True, verbose_name="减按计税比例")
    search_result_revcou = models.CharField(max_length=100, blank=True, null=True, verbose_name="本期收入")
    search_result_orgcod = models.CharField(max_length=40, blank=True, null=True, verbose_name="扣缴义务人纳税人识别号")
    search_result_whanam = models.CharField(max_length=80, blank=True, null=True, verbose_name="扣缴义务人名称")
    search_result_ybtses = models.CharField(max_length=100, blank=True, null=True, verbose_name="应补退税额汇总")
    search_result_orgnam = models.CharField(max_length=100, blank=True, null=True, verbose_name="组织名称")
    create_time = models.DateTimeField(blank=True, null=True, auto_now_add=True, editable=True, verbose_name='创建时间')
    modify_time = models.DateTimeField(blank=True, null=True, auto_now=True, editable=True, verbose_name='修改时间')

    def __str__(self):
        return self.search_result_period

    class Meta:
        managed = True
        db_table = 'tax_search_result'
        verbose_name_plural = '个税查询结果'
        verbose_name = '个税查询结果'
